/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package gui;

import javax.swing.JOptionPane;
import observer.Observer;
import NegocioVO.*;
import delegate.RestauranteDelegate;



/**
 *
 * @author nICO
 */
public class Login extends javax.swing.JInternalFrame implements Observer {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	javax.swing.JInternalFrame jInternalFrameLogin;
	private static InicioGUI inicioGUI;
	
	
    /**
     * Creates new form JInternalFrameLogin
     */
    public Login() {
        initComponents();
        RestauranteDelegate.registerObserver(this);
    }

    public static void setInicioGUI(InicioGUI orig)
    {
    	Login.inicioGUI=orig;
    }
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLblUsuario = new javax.swing.JLabel();
        jLblPassword = new javax.swing.JLabel();
        jBtnAceptar = new javax.swing.JButton();
        jBtnCancelar = new javax.swing.JButton();
        jTxtUsuario = new javax.swing.JTextField();
        jPassword = new javax.swing.JPasswordField();

        setClosable(true);
        setTitle("Login");

        jLblUsuario.setText("Usuario:");

        jLblPassword.setText("Password");

        jBtnAceptar.setText("Aceptar");
        jBtnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnAceptarActionPerformed(evt);
            }
        });

        jBtnCancelar.setText("Cancelar");
        jBtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnCancelarActionPerformed(evt);
            }
        });

        jPassword.setText("jPasswordField1");
        jPassword.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jPasswordFocusGained(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLblPassword)
                            .addComponent(jLblUsuario))
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jTxtUsuario, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPassword, javax.swing.GroupLayout.Alignment.LEADING)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addComponent(jBtnAceptar)
                        .addGap(18, 18, 18)
                        .addComponent(jBtnCancelar)))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLblUsuario)
                    .addComponent(jTxtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLblPassword)
                    .addComponent(jPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtnAceptar)
                    .addComponent(jBtnCancelar))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
	@SuppressWarnings("deprecation")
	private void jBtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnAceptarActionPerformed
        
    	EmpleadoVO toLogin=new EmpleadoVO();
    	toLogin.setIdUsuario(jTxtUsuario.getText());
    	toLogin.setPassword(jPassword.getText());
    	RestauranteDelegate.login(toLogin);
    	
    	/*
    	UsuarioDTO usuarioDTO = new UsuarioDTO();
       
        usuarioDTO.setUsuario(jTxtUsuario.getText());
        usuarioDTO.setPassword(jPassword.getText());
        
        System.out.println("el usuario es " + usuarioDTO.getUsuario());
        System.out.println("el Password es " + usuarioDTO.getPassword());
        
        JFReporteInsumos jfReporteInsumos = new JFReporteInsumos();
        jfReporteInsumos.show();
        */
        
        
        //JInternalFrameReposision jIntFrameReposision= new JInternalFrameReposision();
        //jDesktopPane1.add(jIntFrameReposision);
        //jIntFrameReposision.show();
    }//GEN-LAST:event_jBtnAceptarActionPerformed

    private void jBtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnCancelarActionPerformed
        
    	
    	jPassword.setText(""); 
        
        jTxtUsuario.setText("");
    }//GEN-LAST:event_jBtnCancelarActionPerformed

    private void jPasswordFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jPasswordFocusGained
        jPassword.setText(""); 
    }//GEN-LAST:event_jPasswordFocusGained


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnAceptar;
    private javax.swing.JButton jBtnCancelar;
    private javax.swing.JLabel jLblPassword;
    private javax.swing.JLabel jLblUsuario;
    private javax.swing.JPasswordField jPassword;
    private javax.swing.JTextField jTxtUsuario;
    // End of variables declaration//GEN-END:variables

	@Override
	public void update(String CMD, Object Response) {
		
		if("login".equals(CMD)) 
		{
			JOptionPane.showMessageDialog(null, Response);
			MnuPrincipal jfReporteInsumos = new MnuPrincipal();
	        if("Login exitoso".equals(Response.toString()))
	        {
	        	jfReporteInsumos.show();
	        	this.dispose();
	        	Login.inicioGUI.dispose();
	        }
		}
		
	}
}
